package com.lytxmd.boxtest;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;

import com.uuzuche.lib_zxing.activity.ZXingLibrary;

import java.util.HashMap;
import java.util.Stack;

/**
 * Created by zhangyinglong on 2017/5/16.
 */
public class App extends Application{
    private static App mContext;
    public Stack<Activity> store;
    public HashMap<String, Object> mCurActivityExtra;
    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this;
        store = new Stack<>();

        //二维码扫描初始化
        ZXingLibrary.initDisplayOpinion(this);
    }

    public static App getInstance(){
        return mContext;
    }

    /**
     * 记录Activity栈
     */
    private class AutoManagerActivityLifecycle implements ActivityLifecycleCallbacks {

        @Override
        public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
            store.add(activity);
        }

        @Override
        public void onActivityStarted(Activity activity) {

        }

        @Override
        public void onActivityResumed(Activity activity) {

        }

        @Override
        public void onActivityPaused(Activity activity) {

        }

        @Override
        public void onActivityStopped(Activity activity) {

        }

        @Override
        public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

        }

        @Override
        public void onActivityDestroyed(Activity activity) {
            store.remove(activity);
        }
    }

    /**
     * 获取当前Activity
     * @return
     */
    public Activity getCurrActivity(){
        return store.lastElement();
    }

}
